import { AUDIT_STATUS } from '@utility/dict'

export function buildAuditFlowData(steps) {
  if (steps && steps.length) {
    return steps.map(item => {
      const fields = []
      if (item.createTime) {
        fields.push({
          value: item.createTime,
        })
      }
      if (item.reviewProcessList) {
        fields.push({
          label: '审批人',
          value: item.reviewProcessList.map(p => p.userName).join('，'),
        })
      }
      if (item.userName) {
        fields.push({
          label: '执行人',
          value: item.userName,
        })
      }
      if (item.reason) {
        fields.push({
          label: '意见',
          value: item.reason,
        })
      }
      return {
        id: item.id,
        title: AUDIT_STATUS[item.status],
        operated: item.status !== AUDIT_STATUS.init,
        passed: AUDIT_STATUS.passed === item.status,
        fields: fields,
        status: item.status,
        auditPersons: item.reviewProcessList?.map(item => item.reviewBy) || [],
      }
    })
  }
  return null
}
